package cn.tiasen.helloworld;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Page2Activity extends AppCompatActivity {

    private Button btn_1;
    private Button btn_2;
    private EditText et_1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_page2);

        btn_1 = findViewById(R.id.btn_1);
        btn_2 = findViewById(R.id.btn_2);
        et_1 = findViewById(R.id.et_1);

        Intent get_intent = getIntent();
        String params = get_intent.getStringExtra("params");
        et_1.setText(params);

        btn_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        btn_2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String result = et_1.getText().toString();
                if(TextUtils.isEmpty(result)){
                    Toast.makeText(Page2Activity.this,"内容不能为空",Toast.LENGTH_SHORT).show();

                }else{
                    Intent intent = new Intent();
                    intent.putExtra("RESULT",result);
                    setResult(3,intent);
                    finish();
                }
            }
        });


    }
}
